function calendar()
{
	calendar.prototype.pt = 'div1';
	calendar.prototype.id = 'calendar1';
	calendar.prototype.month = 0;
	calendar.prototype.year = 2000;
	calendar.prototype.boxid = 'foundtime';
	
	calendar.prototype.exec = function()
	{
		var obj = document.getElementById(this.pt);
		this.createCalendar(obj);
	}
	
	calendar.prototype.Monthday = function(year, month)
	{
		var theDate=new Date(year + "/"+ month + "/01");   
		var theDayNumOfThisMonth=(new Date(theDate.getFullYear(),theDate.getMonth()+1,0)).getDate();
		return theDayNumOfThisMonth;
	}
	
	calendar.prototype.createCalendar = function(obj)
	{
		var id = this.id;
		var oldObj = document.getElementById(id);
		if (oldObj)
		{ oldObj.parentNode.removeChild(oldObj);}
		
		var doc = document.createElement("div");
		doc.setAttribute('id',id);
		doc.style.cssText = "border:1px solid #ccc;width:200;height:100;position:absolute;background-color:#fff";
		obj.appendChild(doc);
		
		var newObj = document.getElementById(id);
		
		//initialization
		var nowDate = new Date();
		var yyyy = nowDate.getFullYear() + "";
		var mm = nowDate.getMonth()+1;
		
		var thisMonthday = this.Monthday(yyyy,mm);
		var firstday = this.getFirstday(yyyy,mm);
		
		this.month = mm;
		this.year = yyyy;
		
		newObj.innerHTML = this.html(thisMonthday,firstday);
	}
	
	calendar.prototype.getFirstday = function(yyyy,mm)
	{
		var initDay = new Date(yyyy+"/"+mm+"/1");
		var firstday = initDay.getDay();
		return firstday;
	}
	
	calendar.prototype.next = function(yyyy,mm)
	{
		mm++;
		if (mm > 12) { mm = 1; yyyy++;}
		
		var thisMonthday = this.Monthday(yyyy,mm);
		var firstday = this.getFirstday(yyyy,mm);
		
		var newObj = document.getElementById(this.id);
		this.month = mm;
		this.year = yyyy;
		newObj.innerHTML = this.html(thisMonthday,firstday);
	}
	
	calendar.prototype.prev = function(yyyy,mm)
	{
		mm--;
		if (mm < 1) { mm = 12; yyyy--;}
		
		var thisMonthday = this.Monthday(yyyy,mm);
		var firstday = this.getFirstday(yyyy,mm);
		
		var newObj = document.getElementById(this.id);
		this.month = mm;
		this.year = yyyy;
		newObj.innerHTML = this.html(thisMonthday,firstday);
	}
	
	calendar.prototype.html = function(daycount,firstday)
	{
		var tday = new Date();
		var tDay = tday.getDate();
		var tMin = tday.getMinutes();
		var tHour = tday.getHours();
		var tSec = tday.getSeconds();
		var strhtml = "";
		var id = this.id;
		strhtml += "<table width='210' height='150' cellpadding='0' border='0' style='border-collapse: collapse'>";
		strhtml += "<tr><td valign='top'><div align='center'>";
		strhtml += "<table width='210' style='font-size:10px;text-align:center;font-family:verdana' border='0' cellpadding='0' bordercolor='#C0C0C0' style='border-collapse: collapse'>";
		strhtml += "<tr>";
		strhtml += "<td bgcolor='#cccccc'>"
		strhtml += "<a href='javascript:var o = new calendar();o.id=\""+ this.id +"\";o.pt=\""+this.pt+"\";o.prev(\""+this.year+"\",\""+ this.month +"\");'><<</a>";
		strhtml += "</td>";
		strhtml += "<td height='20' colspan='5' bgcolor='#cccccc'>"+ this.year;
		strhtml += " - "+this.month+"</td><td bgcolor='#cccccc'>";
		strhtml += "<a href='javascript:var o = new calendar();o.id=\""+ this.id +"\";o.pt=\""+this.pt+"\";o.next(\""+this.year+"\",\""+ this.month +"\");'>>></a>";
		strhtml += "</td></tr></table>";
		strhtml += "<table width='210' style='font-size:10px;text-align:center;font-family:verdana' border='0' cellpadding='0' bordercolor='#C0C0C0' style='border-collapse: collapse'>";
		strhtml += "<tr>";
		strhtml += "<td height='20'>Mon</td>";
		strhtml += "<td height='20'>Tue</td>";
		strhtml += "<td height='20'>Wed</td>";
		strhtml += "<td height='20'>Thu</td>";
		strhtml += "<td height='20'>Fri</td>";
		strhtml += "<td height='20'>Sat</td>";
		strhtml += "<td height='20'>Sun</td>";
		strhtml += "</tr>";
		var m = 1-firstday;
		for (j=0;j<this.trCount(daycount,firstday);j++)
		{
			strhtml += "<tr>";
				for (n=0;n<7;n++)
				{
					var fulltime = this.year + "-" + this.month + "-" + m;
					if (m>daycount || m<1)
					{
						strhtml += "<td height='30' width='30'>&nbsp;</td>";
					}
					else{
						if (m==tDay)
						{
							strhtml += "<td height='30' width='30' style='border:1px solid #ff0000' style='cursor:hand' onmouseover='this.bgColor=\"#cadef7\"' onmouseout='this.bgColor=\"\";' onclick='var o = new calendar();o.id=\""+ this.id +"\";o.pt=\""+this.pt+"\";o.boxid=\""+ this.boxid +"\";o.choose(\""+fulltime +"\");'>"+m+"</td>";
						}else{
						strhtml += "<td height='30' width='30' onclick='var o = new calendar();o.id=\""+ this.id +"\";o.pt=\""+this.pt+"\";o.boxid=\""+ this.boxid +"\";o.choose(\""+fulltime +"\");' onmouseover='this.bgColor=\"#cadef7\"' style='cursor:hand' onmouseout='this.bgColor=\"\";'>"+m+"</td>";
						}
					}
					m++;
				}
			strhtml += "<tr>";
		}
		strhtml += "</table>";
		//Time
		strhtml += "<table width='210' style='font-size:10px;font-family:verdana' cellpadding='0' border='0' style='border-collapse: collapse'><tr><td height='20' align='center'>";
		strhtml += "<select id='"+ id +"_hour' style='height:16;width:36;font-size:10px'>";
		for (j=0;j<24;j++){
			var hours = "";
			if ((j+"").length == 1){ hours = "0"+j;}else{ hours = j;}
			var selected = "";
			if (tHour == j){ selected = " selected "; }
			strhtml += "<option value='"+hours+"' "+ selected +">"+hours+"</option>";
		}
		strhtml += "</select>";
		strhtml += ":<select id='"+id+"_minute' style='height:16;width:36;font-size:10px'>";
		for (j=0;j<60;j++){
			var min = "";
			if ((j+"").length == 1){ min = "0"+j;}else{ min = j;}
			var selected = "";
			if (tMin == j){ selected = " selected "; }
			strhtml += "<option value='"+min+"' "+selected+">"+min+"</option>";
		}
		strhtml += "</select>";
		strhtml += ":<select id='"+id+"_second' style='height:16;width:36;font-size:10px'>";
		for (j=0;j<60;j++){
			var sec = "";
			var selected = "";
			if (tSec == j){ selected = " selected "; }
			if ((j+"").length == 1){ sec = "0"+j;}else{ sec = j;}
			strhtml += "<option value='"+sec +"' "+ selected  +">"+sec +"</option>";
		}
		strhtml += "</select>";
		strhtml += " - <a href='javascript:;' onclick='closeit(\""+ this.id +"\")'>Close</a> - </td></tr></table>";
		strhtml += "</div>";
		strhtml += "</td></tr>";
		strhtml += "</table>";
		strhtml += "<iframe width='100%' style='position:absolute; top:0px; z-index:-1;border-style:none' frameborder='0' border='0' marginwidth='1' marginheight='1' scrolling='no' height='99%'></iframe>";
	
		return strhtml;
	}
	
	calendar.prototype.choose = function(v)
	{
		var id = this.id;
		var full = v + " " + document.getElementById(id + '_hour').value + ":" + document.getElementById(id+'_minute').value + ":" + document.getElementById(id+'_second').value;		document.getElementById(this.boxid).value = full;
		
		var oldObj = document.getElementById(id);
		if (oldObj)
		{ oldObj.parentNode.removeChild(oldObj);}
	}
	
	calendar.prototype.trCount = function(daycount,firstday)
	{
		var remain = daycount - (7-firstday);
		
		var tr = this.computing(remain,7) + 1;
		return tr;
	}
	
	calendar.prototype.computing = function(a,b)
	{
		if (a % b == 0){ return a / b;}
		else { return Math.floor(a/b)+1;}
	}
	
}

function closeit(id)
{
	var obj = document.getElementById(id);
	if (obj)
	{
		obj.parentNode.removeChild(obj);
	}
}